package org.nci.platform.workflow.controller;

import cn.hutool.core.lang.tree.Tree;
import gh.priv.general.common.vo.PageResult;
import gh.priv.general.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.nci.platform.workflow.dto.FlowRolePageQuery;
import org.nci.platform.workflow.dto.FlowRoleQuery;
import org.nci.platform.workflow.dto.FlowUserPageQuery;
import org.nci.platform.workflow.dto.FlowUserQuery;
import org.nci.platform.workflow.expand.system.entity.WorkflowCategory;
import org.nci.platform.workflow.expand.system.entity.WorkflowRole;
import org.nci.platform.workflow.expand.system.entity.WorkflowUser;
import org.nci.platform.workflow.expand.system.service.WorkflowCategoryService;
import org.nci.platform.workflow.expand.system.service.WorkflowDeptService;
import org.nci.platform.workflow.expand.system.service.WorkflowRoleService;
import org.nci.platform.workflow.expand.system.service.WorkflowUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户角色
 * </p>
 *
 * @author Tony
 * @date 2021-04-03
 */
@Slf4j
@Tag(name = "用户角色")
@RestController
@RequestMapping("/flowable")
public class FlowSystemController {
    @Resource
    private WorkflowUserService workflowUserService;

    @Resource
    private WorkflowRoleService workflowRoleService;

    @Resource
    private WorkflowDeptService workflowDeptService;
    @Resource
    private WorkflowCategoryService workflowCategoryService;

    @PostMapping(value = "/user/page")
    @Operation(summary = "用户分页列表")
    public Result<PageResult<WorkflowUser>> userPage(@RequestBody FlowUserPageQuery query) {
        return Result.success(workflowUserService.selectUserPage(query));
    }

    @PostMapping(value = "/user/list")
    @Operation(summary = "用户列表")
    public Result<List<WorkflowUser>> userList(@RequestBody FlowUserQuery query) {
        return Result.success(workflowUserService.selectUserList(query));
    }

    @Operation(summary = "指定流程办理组列表")
    @PostMapping("/role/list")
    public Result<List<WorkflowRole>> roleList(@RequestBody FlowRoleQuery role) {
        List<WorkflowRole> list = workflowRoleService.selectRoleList(role);
        return Result.success(list);
    }

    @PostMapping(value = "/role/page")
    @Operation(summary = "角色分页列表")
    public Result<PageResult<WorkflowRole>> rolePage(@RequestBody FlowRolePageQuery query) {
        return Result.success(workflowRoleService.selectRolePage(query));
    }

    @PostMapping(value = "/category/list")
    @Operation(summary = "流程分类")
    public Result<List<WorkflowCategory>> categoryList() {
        return Result.success(workflowCategoryService.selectCategoryList());
    }

    @GetMapping("/dept/tree")
    @Operation(summary = "部门树")
    public Result<List<Tree<String>>> deptTree() {
        return Result.success(workflowDeptService.deptTree());
    }


}
